<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('信息资讯列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="cateId" name="cateId" />
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <label>发布时间：</label>
                                <input type="text" class="time-input" placeholder="请选择发布时间" name="releaseTime"/>
                            </li>
                            <li>
                                <label>状态 ：</label>
                                <select name="newsStatus" th:with="type=${@dict.getType('sys_show_hide')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>资讯类别 </label>
                                <div class="input-group">
                                    <input class="form-control required" type="text" onclick="selectDeptTree()" id="treeName">
                                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                </div>
                            </li>
                            <!--
                            <li>
                                <label>点击量：</label>
                                <input type="text" name="clickCount"/>
                            </li>-->
                            <li class="hidden">
                                <label>删除状态：</label>
                                <input type="text" name="deleted" th:value="N"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset();$('#cateId').val('');"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:news:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="system:news:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:news:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:news:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:news:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:news:remove')}]];
        var newsStatusDatas = [[${@dict.getType('sys_show_hide')}]];
        var prefix = ctx + "system/news";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/edit/-1",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "信息资讯",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'subhead',
                    title: '副标题'
                },
                {
                    field: 'subCateName',
                    title: '资讯分类'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    field: 'newsStatus',
                    title: '状态 ',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(newsStatusDatas, value);
                    }
                },
                {
                    field: 'clickCount',
                    title: '点击量'
                },
                {
                    field: 'images',
                    title: '图片',
                    formatter: function(value, row, index) {
                        var fileUrl = row.images;
                        if(fileUrl){
                            var fileUrls = fileUrl.split(",");
                            for(var i = 0 ; i < fileUrls.length;i ++){
                                if(i==0){
                                   return $.table.imageView(fileUrls[i]);
                                }
                            }
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /*部门管理-新增-选择父部门树*/
        function selectDeptTree() {
            var cateId = $("#cateId").val();
            if(cateId==""){
                cateId = "1";
            }
            var options = {
                title: '类别选择',
                width: "380",
                url: ctx + "system/newsCategory/selectNewsCategoryTree/"+cateId,
                callBack: function (index, layero){
                    var body = layer.getChildFrame('body', index);
                    $("#cateId").val(body.find('#treeId').val());
                    $("#treeName").val(body.find('#treeName').val());
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }
    </script>
</body>
</html>